ComponentOne Basic Library for UWP
Basic Library Overview / TreeView for UWP / TreeView Behavior / Node Selection
In This Topic
    Node Selection
    In This Topic

    When you click on a node at run time it is automatically marked as selected. Clicking a node will raise the C1TreeView.SelectionChanged event to provide custom functionality. To have the nodes marked as selected without clicking them you can enable the C1TreeViewItem.IsSelected property.

    When the user selects a new item, the C1TreeView fires the C1TreeView.SelectionChanged event. You can then retrieve the item that was selected using the C1TreeView.SelectedItem property.

    There're several ways to do this. One is to assign additional data to the Tag property of each C1TreeViewItem as you create them. Later, you can inspect the Tag property to retrieve the information. For example:

    Visual Basic
    Copy Code
    ' Create a node and assign some data to its Tag property
    Dim item As New C1TreeViewItem()
    item.Header = "Beverages"
    item.Tag = beveragesID
    

    C#
    Copy Code
    // Create a node and assign some data to its Tag property
    C1TreeViewItem item = new C1TreeViewItem();
    item.Header = "Beverages";
    item.Tag = beveragesID;
    

    Later, use the information in whatever way you see fit:

    Visual Basic
    Copy Code
    Dim item As C1TreeViewItem = _tv.SelectedItem
        ' Handle beverages node
    If TypeOf item.Tag Is Integer AndAlso CInt(item.Tag) = beveragesID Then
    End If
    

    C#
    Copy Code
    C1TreeViewItem item = _tv.SelectedItem;
    if (item.Tag is int && (int)item.Tag == beveragesID)
    {
        // Handle beverages node
    }
    

    If the C1TreeView.SelectionMode property is set to Multiple then multiple nodes can be selected at one time by holding down the control key while mouse clicking multiple nodes. To unselect a node, click on it again.

    The nodes are marked as selected in the following C1TreeView:

     

    See Also